package com.openx.xoj.controller;

import com.openx.xoj.model.Teacher.Examination;
import com.openx.xoj.service.ExaminationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/examination")
public class ExaminationController {

    @Autowired
    private ExaminationService examinationService;

    @PostMapping("/create")
    public int createExamination(@RequestBody Examination examination) {
        System.out.println("****************************************");
        System.out.println("Received Examination: " + examination);
        System.out.println("****************************************");
        return examinationService.createExamination(examination);
    }

    @GetMapping("/all")
    public List<Examination> getAllExaminations(){
        return examinationService.getAllExaminations();
    }

    @DeleteMapping("/delete/{id}")
    @ResponseBody
    public boolean deleteExaminationById(@PathVariable Integer id) {
        return examinationService.deleteExaminationById(id);
    }

    @PutMapping("/update")
    @ResponseBody
    public boolean updateExaminationById(@RequestBody Examination examination) {
        return examinationService.updateExaminationById(examination);
    }

    @GetMapping("/getLastExaminationId")
    public ResponseEntity<Integer> getLastExaminationId() {
        int lastId = examinationService.getLastExaminationId();
        return ResponseEntity.ok(lastId);
    }
}
